package research.ui.editors.tableeditors.sample;

import research.domain.ParameterValue;
import research.entity.Entity;
import research.ui.editors.tableeditors.EntityCellModifier;
import research.ui.editors.tableeditors.EntityLabelProvider;
import research.ui.editors.tableeditors.EntityTableEditor;

public class SampleCellModifier extends EntityCellModifier {

	public SampleCellModifier(EntityTableEditor viewer) {
		super(viewer);
	}
	
	@Override
	public boolean canModify(Object element, String property) {
		return getColumnIndex(property) == 2;
	}

	@Override
	protected Object getValue(Entity entity, int columnIndex) {
		ParameterValue par = (ParameterValue) entity;

		switch (columnIndex) {
		case 0:
			return par.getParameter().getName();
		case 1:
			return par.getParameter().getUnits();
		case 2:
			return EntityLabelProvider.render(par.getValue());
		case 3:
			return ((SampleTableEditor) viewer).getDefaultParameterValue(par.getParameter());
		case 4:
			return EntityLabelProvider.render(par.getParameter().getLow());
		case 5:
			return EntityLabelProvider.render(par.getParameter().getHigh());
		default:
		}
		return null;
	}

	@Override
	protected void modify(Entity entity, int columnIndex, Object value) {
		ParameterValue par = (ParameterValue) entity;
		switch (columnIndex) {
		case 2:
			par.setValue(parseDouble(value, Double.NaN));
			break;
		default:
		}
	}

}
